package br.com.application.adapter;

import java.util.List;

import br.com.application.pojos.Mensagens;

import br.com.application.activities.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MensagemAdapter extends BaseAdapter {

	private List<Mensagens> lista;
	Context context;
	public MensagemAdapter(List<Mensagens> lista, Context context){
		this.context = context;
		this.lista = lista;
	}
	
	public int getCount() {
		return lista.size();
	}

	public Object getItem(int position) {
		return lista.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Mensagens msg = (Mensagens) getItem(position);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(R.layout.mensagemlist ,null);
		TextView titulo = (TextView) v.findViewById(R.id.txtTitulo);
		titulo.setText(msg.getTitulo());
		TextView data = (TextView) v.findViewById(R.id.txtDataInicial);
		data.setText(msg.getDataInicial());
		ImageView img = (ImageView) v.findViewById(R.id.imgMsg);
		if(msg.getLida()==1){
			img.setImageResource(R.drawable.ready);
		}else{
			img.setImageResource(R.drawable.notready);
		}
		return v;
	}

}
